package com.softlab.retailwholesalesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softlab.retailwholesalesystem.entity.AuthorityEntity;
import com.softlab.retailwholesalesystem.entity.MenuEntity;
import com.softlab.retailwholesalesystem.mapper.AuthorityMapper;
import com.softlab.retailwholesalesystem.mapper.MenuMapper;
import com.softlab.retailwholesalesystem.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> implements IMenuService {

    @Autowired
    MenuMapper mapper;

    @Autowired
    AuthorityMapper authorityMapper;

    @Override
    public List<MenuEntity> getMenuByAuthority(Integer authorId) {
        QueryWrapper<AuthorityEntity> authorityWrapper = new QueryWrapper<>();
        authorityWrapper.eq("role_id",authorId).eq("is_delete",0);
        List<AuthorityEntity> authorityEntities = authorityMapper.selectList(authorityWrapper);
        List<Integer> authorList=new ArrayList<>();
        for (AuthorityEntity authorityEntity : authorityEntities) {
            authorList.add(authorityEntity.getMenuId());
        }
        return mapper.getMenuByAuthority(authorList);
    }
}
